package cn.seocoo.platform.api.controller;


import cn.seocoo.platform.api.util.JSONResult;
import cn.seocoo.platform.common.utils.StringUtils;
import cn.seocoo.platform.version.domain.AppVersion;
import cn.seocoo.platform.version.service.IAppVersionService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "App版本和上架", description = "App版本和上架")
@RestController
@RequestMapping("/api/version")
public class ApiAppVersionController {



    @Autowired
    private IAppVersionService appVersionService;


    /**
     * App版本
     *
     * @author pyh
     * @date 2019-08-28
     */
    @ApiOperation("App版本")
    @PostMapping("/checkVersion")
    public JSONResult checkVersion(@RequestBody String str) {
        JSONObject json = JSON.parseObject(str);
        AppVersion appVersion = new AppVersion();
        bb:
        try {
            AppVersion appVersionTemp = JSON.parseObject(json.toString(), AppVersion.class);
            if (StringUtils.isEmpty(appVersionTemp.getTerminal())) {
                break bb;
            }
            appVersion = appVersionService.checkVersion(appVersionTemp);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JSONResult.ok(appVersion);
    }

    /**
     * App上架状态
     *
     * @author pyh
     * @date 2019-08-28
     */
    @ApiOperation("App上架")
    @PostMapping("/checkPutAway")
    public JSONResult checkPutAway(@RequestBody String str) {
        JSONObject json = JSON.parseObject(str);
        int i = 0;
        bb:
        try {
            AppVersion appVersionTemp = JSON.parseObject(json.toString(), AppVersion.class);
            if (StringUtils.isEmpty(appVersionTemp.getTerminal())) {
                break bb;
            }
            if (StringUtils.isNull(appVersionTemp.getAppPutaway())) {
                break bb;
            }
            i = appVersionService.checkPutAway(appVersionTemp);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JSONResult.ok(i);
    }



}
